<?php
/**
 * @author thankwsx
 * @version 1.0
 * @created 09-六月-2008 20:16:15
 */
class Ebook extends Controller
{

	public function __construct() {
		parent::__construct();
		$this->load->model("Ebook_model","ebook");
//		$this->load->model("Catagory_model","catagory");
	}

	function index($catagory = '') {

		if(!empty($catagory)) {
			$id = $this->catagory->getIdByCatagory($catagory);	//分类目录id
			$search = array(
				'catagory_id'=>$id
			);
		} else $search = array();
		$result = $this->ebook->retriveby('',$search,'',50);
		$data = array(
			"ebooks" => $result
		);
		$this->load->view("ebook_list",$data);
	}

	function admin() {
		$data['data'] = array("ebook"=>array("ebooks"=>$this->ebook->getBooks(1,"id")));
//		var_dump($data['data']);
		$this->load->view("admin",$data);
	}

	function get() {
		$page = $this->input->post("page");
		$sort = $this->input->post("sortname");
		$order = $this->input->post("sortorder");
		$num  = $this->input->post("rp");
		$query = $this->input->post("query");
		$qtype = $this->input->post("qtype");
		$orderby = $sort." ".$order;
		$search = "where ".$qtype." like '%".$query."%'";
		$data['data'] = $this->ebook->getBooks($page,$orderby,$num,$search);
		echo json_encode(array("rows"=>$data['data'],"total"=>$this->ebook->getNums($search),"page"=>(int)$page));
	}
}
?>